<?php

namespace App\Listeners;

use App\Events\ReleasePatent;
use App\Services\ApiSyncService;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;

class SendPatentNotification
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    protected $apiSyncService;

    public function __construct(ApiSyncService $apiSyncService)
    {
        $this->apiSyncService = $apiSyncService;
    }

    /**
     * Handle the event.
     *
     * @param  ReleasePatent $event
     * @return void
     */
    public function handle(ReleasePatent $event)
    {
        try {
            $this->apiSyncService->syncGoods($event->goods);
        } catch (\Exception $exception) {
            throw new \Exception('同步失败');
        }
    }
}
